package com.zk.algorithm.math;

import com.zk.algorithm.Utils;
import com.zk.algorithm.annotation.LeetCodeExplore;
import com.zk.algorithm.annotation.Medium;

/**
 * 阶乘有多少个 0
 */
@LeetCodeExplore
@Medium
public class FactorialTrailingZeroes {

    public static void main(String...args) {
        FactorialTrailingZeroes factorialTrailingZeroes = new FactorialTrailingZeroes();
        int result = factorialTrailingZeroes.trailingZeroesLogN(33);
        Utils.println(result);
    }

    // LogN 算法
    public int trailingZeroesLogN(int n) {
        int ans = 0;

        while (n > 0) {
            n = n / 5;
            ans += n;
        }

        return ans;
    }

    // 33
    public int trailingZeroes(int n) {
        int ans = 0;

        n = n / 5 * 5;

        while (n >= 1) {

            int temp = n;
            while (temp % 5 == 0) {
                temp = temp / 5;
                ans++;
            }

            n -= 5;
        }

        return ans;
    }

}
